package com.itheima;

import java.util.Scanner;

//键盘录入3个整数, 并将它们都存入到数组中, 然后获取所有元素之和, 并打印结果.
public class Demo03 {
    public static void main(String[] args) {
        //定义一个int类型的数组, 数组名叫: a, 数组的长度是3.
        int[] a = new int[3];
        try {
            //定义一个键盘录入对象
            Scanner scanner = new Scanner(System.in);
            //for循环请录入第"+(i+1)+"个数字
            for (int i = 0; i < 3; i++) {
                System.out.println("请输入第" + (i + 1) + "个数字");
                a[i] = Integer.parseInt(scanner.nextLine());
            }
            int sum = 0;
            //for循环求和
            for (int i = 0; i < a.length; i++) {
                sum += a[i];
            }
            System.out.println(sum);
        } catch (Exception e) {
            System.out.println("程序出错：" + e.getMessage());
        }
    }
}
